//装饰者模式

// 抽象构件角色
interface Component {
    void operate();
}

// 具体构件角色
class ConcreteComponent implements Component {
    public void operate() {
        System.out.println("ConcreteComponent operate.");
    }
}

// 抽象装饰类
abstract class Decorator implements Component {
    protected Component component;

    public Decorator(Component component) {
        this.component = component;
    }

    public void operate() {
        component.operate();
    }
}

// 具体装饰类A
class ConcreteDecoratorA extends Decorator {
    public ConcreteDecoratorA(Component component) {
        super(component);
    }

    public void operate() {
        super.operate();
        addBehavior();
    }

    private void addBehavior() {
        System.out.println("ConcreteDecoratorA behavior.");
    }
}

// 具体装饰类B
class ConcreteDecoratorB extends Decorator {
    public ConcreteDecoratorB(Component component) {
        super(component);
    }

    public void operate() {
        super.operate();
        addBehavior();
    }

    private void addBehavior() {
        System.out.println("ConcreteDecoratorB behavior.");
    }
}

